package org.example;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/test")
public class TestController {

    @Value("${server.port}")
    private String port;

    @SentinelResource(value = "test", blockHandler = "testBlockHandler")
    @GetMapping("/{id}")
    public String test(@PathVariable Integer id) throws InterruptedException {
        Thread.sleep(2000);
        return id + "upms!" + port;
    }

    public String testBlockHandler(Integer id, BlockException e) {
        e.printStackTrace();
        return id + "testBlockHandler";
    }
}
